package main

import (
	"net/http"
	_ "ones-objects/objects-api/init"
	"ones-objects/config"
	"time"
	"ones-objects/objects-api/objects"
	"ones-objects/objects-api/heartbeat"
	"ones-objects/objects-api/locate"
)

func main()  {
	go heartbeat.ListenHeartbeat()

	mux := http.DefaultServeMux
	mux.Handle("/objects/", http.HandlerFunc(objects.Handler))
	mux.Handle("/locate/", http.HandlerFunc(locate.Handler))

	server := &http.Server{
		Addr: config.GetString("app.server.port"),
		ReadTimeout: time.Duration(config.GetInt64Def("app.server.readtimeout", 100)) * time.Millisecond,
		WriteTimeout: time.Duration(config.GetInt64Def("app.server.writetimeout", 100)) * time.Millisecond,
		Handler:mux,
	}
	server.ListenAndServe()
}
